<?php

namespace App\Http\Controllers\Admin\Sys;

use App\Http\Responses\ResponseDto;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\View;

class RobotsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response{cate}/{subcategory}
     */
    public function index(Request $request)
    {
        $filename = Config::get("common.robots_url");
        $contents = "";
        if(file_exists($filename)){
            $handle = fopen($filename, "r");
            if( filesize ($filename) >0){
                $contents = fread($handle, filesize ($filename));
                fclose($handle);
                $contents = trim($contents);
            }

        }

        return View::make('admin.sys.robots')
            ->withRobotstext($contents)
            ->withAssets($request['ASSETS']);
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        $filename = Config::get("common.robots_url");
        $handle = fopen($filename, "w");//��ȡ�������ļ�ʱ����Ҫ���ڶ����������ó�'rb'
        fwrite($handle, $request->input("value"));
        fclose($handle);
        return ResponseDto::createResObj(trans("admin/message.update_success"),ResponseDto::$SUCCESS);

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {

    }
}
